package pratice7;

public class Vehicle {
    private String name;
    private double speed;
    private double volume;

    public Vehicle(String name, double speed, double volume) {
        this.name = name;
        this.speed = speed;
        this.volume = volume;
    }

    public void showInfo() {
        System.out.println("交通工具名称：" + name);
        System.out.println("交通工具速度：" + speed + " km/h");
        System.out.println("交通工具体积：" + volume + " m³");
    }

    public void speedUp(double increase) {
        if (increase > 0) {
            this.speed += increase;
            System.out.println(name + " 加速了 " + increase + " km/h，当前速度为：" + speed + " km/h");
        } else {
            System.out.println("加速量必须大于0！");
        }
    }

    public void speedDown(double decrease) {
        if (decrease > 0 && speed > decrease) {
            this.speed -= decrease;
            System.out.println(name + " 减速了 " + decrease + " km/h，当前速度为：" + speed + " km/h");
        } else {
            System.out.println("减速量必须大于0且不能超过当前速度！");
        }
    }
}

public class VehicleTest {
    public static void main(String[] args) {
        Vehicle car = new Vehicle("轿车", 120, 2.5);
        car.showInfo();

        car.speedUp(20);
        car.speedDown(15);
        car.speedDown(30); // 减速量超过当前速度，输出提示信息

        Vehicle bus = new Vehicle("公交车", 80, 50);
        bus.showInfo();

        bus.speedUp(10);
        bus.speedDown(5);
        bus.speedDown(3); // 减速量小于0，输出提示信息
    }
}
